package com.cc.main;

import java.util.HashMap;
import java.util.Map;

import com.cc.main.cmd.AddKeywordCmd;
import com.cc.main.cmd.HelpCmd;
import com.cc.main.cmd.NotepadCmd;
import com.cc.main.cmd.PathCmd;
import com.cc.main.cmd.PrintEnvCmd;
import com.cc.main.cmd.RunCmd;
import com.cc.main.cmd.SaveCmd;
import com.cc.main.cmd.SelectCmd;
import com.cc.main.cmd.SettimeCmd;
import com.cc.main.problems.bean.CmdBean;
import com.cc.main.util.CcExceeption;

public class Const {

	public final static String vers = "1.3.230217";
	public final static String LOG_FILE_SUFFIX = ".log";
	
	//命令集合
	public final static String MHelpCmd = "help";
	public final static String MQuitCmd = "quit";
	public final static String MSelectCmd = "select";
	public final static String MPathCmd = "path";
	public final static String MSaveCmd = "save";
	public final static String MPrintEnvCmd = "env";
	public final static String MSettimeCmd = "time";
	public final static String MAddKeywordCmd = "keyword";
	public final static String MRunCmd = "run";
	public final static String MNotepadCmd = "notepad";
	
	public static Map<Integer,CmdBean> pblMap = new HashMap<Integer, CmdBean>();
	public static Map<String,CmdBean> onlyCmdMap = new HashMap<String, CmdBean>();
	public static String NOTEPAD_PATH = ""; // notepad 程序路径，用于打开文件使用
	
	static {
		//命令
		addCmdBean(MPathCmd,"设置日志路径",PathCmd.class);
		addCmdBean(MSelectCmd,"选择问题",SelectCmd.class);
		addCmdBean(MRunCmd,"运行程序",RunCmd.class);
		addCmdBean(MSettimeCmd,"设置时间范围",SettimeCmd.class);
		addCmdBean(MAddKeywordCmd,"添加关键字",AddKeywordCmd.class);
		addCmdBean(MSaveCmd,"保存结果",SaveCmd.class);
		addCmdBean(MPrintEnvCmd,"当前环境变量",PrintEnvCmd.class);
		addCmdBean(MNotepadCmd,"打开文件",NotepadCmd.class);
		addCmdBean(MHelpCmd,"帮助信息",HelpCmd.class);
	};
	
	public static CmdBean getCmdBean(Object obj) throws CcExceeption {
		CmdBean cmd = null;
		if(obj instanceof String) {
			cmd = onlyCmdMap.get(obj);
		}else {
			cmd = pblMap.get(obj);
		}
		if(cmd == null) {
			throw new CcExceeption("");
		}
		return cmd;
	}
	
	private static void addCmdBean(String cmd,String descrips,Class cls) {
		onlyCmdMap.put(cmd, new CmdBean(cls, descrips));
	}
}
